import { createStore, Store } from 'vuex'
import { InjectionKey } from 'vue'

// 手动声明 state 类型
export interface State {
  MENU_LIST: any,
  CLASS_LIST: any,
  TOKEN: any,
  status: number,
  USER: any,
}

// 定义注入类型
export const key: InjectionKey<Store<State>> = Symbol()

export const store =  createStore<State>({
  state: {
    MENU_LIST: {},
    CLASS_LIST: {},
    TOKEN: '',
    status: 0,
    USER: {},
  },
  mutations: {
    addMENU_LIST (state,n:any) {
      state.MENU_LIST  = n;
    },
    addCLASS_LIST (state,n:any) {
      state.CLASS_LIST  = n;
    },
    addTOKEN(state,n) {
      state.TOKEN = n;
    },
    addSTATUS(state,n) {
      state.status = n;
    },
    addUSER(state,n) {
      state.USER = n;
    },
    removeALL(state){
      state.TOKEN = '';
      state.status = 0;
      state.USER = {}  ;
    }
  },
  actions: {
    actMENU_LIST (context,n) {
      context.commit('addMENU_LIST',n)
    },
    actCLASS_LIST (context,n) {
      context.commit('addCLASS_LIST',n)
    },
    actTOKEN(context,n) {
      context.commit('addTOKEN',n)
    },
  },
  modules: {
  }
})
